package com.second.app.obj;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;

public class Person implements Serializable {

    private String name;

    private String age;

    public Person(String name, String age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()){
            return false;
        }
        Person person = (Person) o;
        return Objects.equals(name, person.name) && Objects.equals(age, person.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public static void main(String[] args) {
        Person p1 = new Person("张三", "18");
        Person p2 = new Person("张三", "18");
        System.out.println(p1==p2);
        System.out.println(p1.equals(p2));
        System.out.println("================");
        HashMap<Object, String> map = new HashMap<>();
        System.out.println(p1.hashCode());
        System.out.println(p2.hashCode());
        map.put("abc","美国");
        map.put(p1.hashCode(),"美国1");
        map.put(p2.hashCode(),"美国");
        System.out.println(map.get(p1.hashCode()));
        System.out.println(map.get(p2.hashCode()));
    }
}
